<?php
session_start();
?>
<html>
<head>
<style type="text/css">
<!--
body {
	background-color: #FFFFFF;
}
-->
</style>
</head>
<body><?php
     include("../../MerchandiseBay/conn.php");

     $name=$_SESSION['username'];
	 $orders=$_POST['orderList'];
     $reservationDate=$_REQUEST['reservationdate'];
	 $reservationTime=$_REQUEST['reservationtime'];
      
     $sql="INSERT INTO `reservation` (`name` ,`reservationdate` , `reservationtime`) VALUES 
	 								('$name', '$reservationDate', '$reservationTime')";

    $qry=mysql_query($sql,$conn);//insert reservation data into table reservation
	$reservationId=mysql_insert_id();
	$List = split(',', $_REQUEST['orderList']);
	//$List[0] === 'X01=3'


	 if($qry==true)
	 {
	 	for($counter = 0; $counter < count($List); $counter+=1)
		{
			$item = split('=',$List[$counter]);
	 		$sqlDetail = "INSERT INTO `reservationdetail` (`reservationId`, `code`, `quantity`) VALUES
	 					('$reservationId', '$item[0]', '$item[1]')";
			mysql_query($sqlDetail,$conn);
		}
		
    	echo  "<script language=javascript>
           		window.alert('Your reservation recorded. Thanks for your supported. Your reservation id is $reservationId.');
           		window.location.assign('Welcome.html');
		   		</script>";	
	}
	else
	{
	
	     die (mysql_error());
	}
	?>
</body>
</html>